<?php

namespace App\Service\Cruise\Check;

use App\Service\BaseService;
use App\Models\Cruise\CruiseCheckAgainstShopMappingModel;

class CruiseCheckAgainstShopMappingsService extends BaseService
{

    /**
     * 更新门店违约函版本号
     * @param int $shopId
     * @param int $shopCode
     */
    public static function addAgainstVersionByShopId(int $shopId, int $shopCode)
    {
        //通过shopId获得违约函版本号
        $version = CruiseCheckAgainstShopMappingModel::getVersionByShopId($shopId);
        if (!$version) {
            $version = self::getAgainstVersionByShopCode($shopCode);
            $data    = [
                'shopId'  => $shopId,
                'version' => $version,
            ];
            CruiseCheckAgainstShopMappingModel::addCheckAgainstShop($data);
        }
    }

    /**
     * 通过门店Code获得违约函版本号
     * @param int $shopCode
     * @return string
     */
    public static function getAgainstVersionByShopCode(int $shopCode): string
    {
        if ($shopCode <= 128) {
            return 'v1.0';
        } elseif ($shopCode <= 501) {
            return 'v2.0';
        } elseif ($shopCode <= 2386) {
            return 'v3.0';
        }
        return 'v4.0';
    }


}
